<?php
namespace jy_yangjidan;
defined('BY_JYA') or exit('error');
/*
	任务
*/
class task extends \plugin{
    public function upmyji($setting=array()){
		if($setting){
			$this->setting=$setting;
		}
        $daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
		//平台投喂
        $list = pdo_getall('jy_yangjidan_myji',array('uniacid'=>$_SESSION['uniacid'],'isweitou'=>1,'weitime <'=>$daytime));
		$dj_dayfee=$this->setting['dj_dayfee'];
        foreach($list as $item){
			pdo_update('jy_yangjidan_myji',array('weitime'=>time(),'lsfee +='=>$dj_dayfee,'lsday +='=>1),array('id'=>$item['id'],'uniacid'=>$_SESSION['uniacid']));
        }
		//饿死
		$this->setting['dj_delday']=$this->setting['dj_delday']?:5;
		$day5time=$daytime-$this->setting['dj_delday']*24*3600;
		pdo_update('jy_yangjidan_myji',array('status'=>3),array('uniacid'=>$_SESSION['uniacid'],'status'=>array(1,2),'weitime <'=>$day5time));
		//饥饿
		$day3time=$daytime-1*24*3600;
		pdo_update('jy_yangjidan_myji',array('status'=>2),array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'weitime <'=>$day3time));
		//生蛋
		$canshengjd=true;
		if($this->setting['dj_huitype']){
			$wkey=date("w");
			if(!$wkey || $wkey==6){
				$canshengjd=false;
			}
		}
		if($canshengjd){
			$list = pdo_getall('jy_yangjidan_myji',array('uniacid'=>$_SESSION['uniacid'],'lsyudan >'=>0,'status'=>1,'jdtime <'=>$daytime));
			foreach($list as $item){
				$this->model('model')->addjilog($item,4);
			}
		}
		//饿1天减预测鸡蛋
		$list = pdo_getall('jy_yangjidan_myji',array('uniacid'=>$_SESSION['uniacid'],'lsyudan >'=>0,'status'=>2,'jianjdtime <'=>$daytime));
		foreach($list as $item){
			$this->model('model')->addjilog($item,5);
		}
		//结束
		pdo_update('jy_yangjidan_myji',array('status'=>4),array('uniacid'=>$_SESSION['uniacid'],'lsyudan'=>0,'status'=>array(1,2)));
        return true;
    }
}